package com.wang.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wang.mapper.DevControlFunMapper;
import com.wang.pojo.DevControlFun;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author wcy
 * @date 2023-07-19 9:36
 */
@Service
@Transactional
public class DevControlFunServiceImpl extends ServiceImpl<DevControlFunMapper,DevControlFun> implements  DevControlFunService {

    @Autowired
    private DevControlFunMapper devControlFunMapper;

    @Override
    public void updateDevControlFunNowStatus(Integer funId, Integer nowStatus) {
        devControlFunMapper.update(null,new LambdaUpdateWrapper<DevControlFun>()
                .eq(DevControlFun::getFunId,funId)
                .set(DevControlFun::getNowStatus,nowStatus)
        );
    }

    @Override
    public List<DevControlFun> selectDevControlFunByDevId(Integer devId) {
        return devControlFunMapper.selectList(new LambdaQueryWrapper<DevControlFun>().eq(DevControlFun::getDevId,devId));
    }

    @Override
    public void editNowStatusByFunNameAndDevId(Integer devId, String funName1, Integer nowStatus) {
        devControlFunMapper.update(null,new LambdaUpdateWrapper<DevControlFun>().eq(DevControlFun::getDevId,devId)
            .eq(DevControlFun::getFunName,funName1)
                .set(DevControlFun::getNowStatus,nowStatus)
        );
    }

    @Override
    public DevControlFun selectDevControlFunByDevIdAndFunName(Integer devId, String funName1) {
        return devControlFunMapper.selectOne(new LambdaQueryWrapper<DevControlFun>().eq(DevControlFun::getDevId,devId).eq(DevControlFun::getFunName,funName1));
    }
}
